package cn.yuan.xiaoyu.testmodule.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.yuan.xiaoyu.R;
import cn.yuan.xiaoyu.commonmodule.utils.T;

/**
 * Created by yukuoyuan on 2017/3/31.
 */

public class TestRecycleviewAdapter extends RecyclerView.Adapter<TestRecycleviewAdapter.MyHolder> {
    private List<String> list;
    private Context context;

    public TestRecycleviewAdapter(Context context, List<String> list) {
        this.list = list;
        this.context = context;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_test_recycleview, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, final int position) {
        holder.tvItemTestRecycleview.setText(list.get(position));
        holder.tvItemTestRecycleview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                T.show(context, "dijige " + position, 0);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_item_test_recycleview)
        TextView tvItemTestRecycleview;

        public MyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
